﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demos.DesignPatterns._23_访问者模式
{
    /// <summary>
    /// 价格计算器
    /// </summary>
    public class PriceCalculator: IVisitor
    {
        public decimal TotalPrice { get; private set; }
        /// <summary>
        /// 计算普通商品总价
        /// </summary>
        /// <param name="product"></param>
        public void Visit(RegularProduct product)
        {
            TotalPrice += product.Price * product.Quantity;
            Console.WriteLine($"计算普通商品总价={TotalPrice}....");
        }
        /// <summary>
        /// 礼品卡不需要计算总价
        /// </summary>
        /// <param name="giftCard"></param>
        public void Visit(GiftCard giftCard)
        {
            // 礼品卡不计入总价
            Console.WriteLine("使用了礼品卡,礼品卡不计入总价...");
        }

        /// <summary>
        /// 计算打折商品总价
        /// </summary>
        /// <param name="product"></param>
        public void Visit(DiscountedProduct product)
        {
            TotalPrice += product.DiscountedPrice * product.Quantity;
            Console.WriteLine($"计算打折商品总价={TotalPrice}");
        }

    }
}
